<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>非父子组件之间的传递</title>
</head>

<body>
    <div id="rood">
        <hello></hello>
        <nihao></nihao>
    </div>
    <script src="../libs/vue/vue.js"></script>
    <script>
        const bus = new Vue()
        new Vue({
            el: '#rood',
            data: {

            },
            components: {
                'hello': {
                    template: `
                    <div>
                        我是大哥
                        <button @click="giveme">借钱</button>
                    </div>
                    `,
                    methods: {
                        giveme() {
                            bus.$emit('givemoney')
                        }
                    },
                },
                'nihao': {
                    template: `
                    <div>
                        我是二哥
                        <button v-if='seen'>我的钱啊~55555555555</button>
                    </div>
                    `,
                    data() {
                        return {
                            seen: false
                        }
                    },
                    created() {
                        bus.$on('givemoney', () => {
                            console.log('二哥存了钱')
                            this.seen = true
                        })
                    },
                }
            }
        })
    </script>
</body>

</html>